package com.szl.group;

import com.google.common.hash.Funnels;
import com.szl.group.utils.bloom.BloomFilterHelper;
import com.szl.group.utils.bloom.RedisBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;

import javax.annotation.PostConstruct;
import java.nio.charset.Charset;

/*@EnableScheduling //开启定时任务*/
@EnableAsync    //开启异步线程池
@SpringBootApplication
public class DeltaApplication implements ApplicationRunner {


    private static BloomFilterHelper<CharSequence> bloomFilterHelper;

    public static void main(String[] args) {
        SpringApplication.run(DeltaApplication.class, args);
    }

    @Autowired
    RedisBloomFilter redisBloomFilter;



    @PostConstruct
    public void init() {
        bloomFilterHelper = new BloomFilterHelper<>(Funnels.stringFunnel(Charset.defaultCharset()), 1000, 0.1);
    }


    @Override
    public void run(ApplicationArguments args) throws Exception {
/*

        //******* Redis集群测试布隆方法*********
        int j = 0;
        for (int i = 0; i < 100; i++) {
            redisBloomFilter.addByBloomFilter(bloomFilterHelper, "bloom", i+"");
        }
        for (int i = 0; i < 1000; i++) {
            boolean result = redisBloomFilter.includeByBloomFilter(bloomFilterHelper, "bloom", i+"");
            if (!result) {
                j++;
            }
        }
        System.out.println("漏掉了" + j + "个");*/
    }



}
